home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cug236.zip / XC.C < prev    next >
Text File  |  1980-01-02  |  26KB  |  884 lines

  1. /*
  2.     HEADER:        CUG000.00;
  3.     TITLE:        Cross Reference Generator;
  4.     DATE:        04/05/1987;
  5.     DESCRIPTION:    "Generic version of programmer's cross-reference
  6.             generator originally for BDS.";
  7.     VERSION:    2.2;
  8.     KEYWORDS:    Cross Reference;
  9.     FILENAME:    XC.C;
  10.     SEE-ALSO:    CUG126, CUG171;
  11.     COMPILERS:    vanilla;
  12.     AUTHORS:    Phillip N. Hisley, W. H. Rauser, W. C. Colley III;
  13. */
  14.  
  15. /************************************************************************/
  16. /*   5 APR 1987      Portable C Conversion        WCC                */
  17. /*     -  Epson init string changed from hex (\x00) to octal (\000).    */
  18. /*     -  Use () with A?(c=B):(c=C) for portability.  If it's an error, */
  19. /*        it seems to be a very common one.            */
  20. /*     -  Made use of host compiler's strcmp() and strcpy() as they are */
  21. /*        usually written in assembly and run faster.        */
  22. /*     -  Globally replaced "alpha_" with "alp_", "alloc_" with        */
  23. /*        "allo_", and "tmpchr" with "tmpch" to avoid multiply    */
  24. /*        defined symbol errors on compilers that only support    */
  25. /*        @$%&*&?>}\~~@# 6-character names.            */
  26. /*     -  Added abs() macro for compilers that don't have one.          */
  27. /*     -  Used some data initialization to kill off some code.        */
  28. /*     -  Made miscellaneous small tweaks for portability.        */
  29. /*     -  Cleaned out old BDS C stuff to improve readability.        */
  30. /*     -  Cleaned up abortion with use of rf_blk.rf_cnt as a pointer    */
  31. /*        link to the next rf_blk.  This construct will NOT work    */
  32. /*        in environments like the MSDOS large model where ints    */
  33. /*        are smaller than pointers!                */
  34. /*                                    */
  35. /*   9-26-83   Microsoft C 1.04     Conversion    WHR            */
  36. /*     -  \t between line numbers and text to fix indenting problem.    */
  37. /*     -  added option -e for output to Epson in condensed print.    */
  38. /*     -  toupper() and isupper() are macros, not functions.        */
  39. /*     -  eliminate side effect in toupper(*++arg) in main().        */
  40. /*     -  change alloc() to malloc().                    */
  41. /*     -  add #define NAMES that are not in stdio.h            */
  42. /*     -  MS-C requires () in statement A?(c=B):(c=C)    error or not??    */
  43. /*                                    */
  44. /*   4-30-83   Computer Innovations C-86 1.31 Conversion    WHR        */
  45. /*     -  #include filename changed to allow a disk drive prefix, D:    */
  46. /*     -  convert if(fprintf(...) == ERROR) lst_err(); to fprintf(..);    */
  47. /*     -  convert if(fopen(...) == ERROR) statements to == NULL.    */
  48. /*     -  C86 requires () in statement A?(c=B):(c=C)    error or not??    */
  49. /*     -  remove getc() == ERROR check in fil_chr().            */
  50. /*     -  convert file conventions from BDS C to C-86.            */
  51. /*     -  comment out BDS unique statements, mark revised statements.    */
  52. /*      keep all BDS statements to document conversion effort.    */
  53. /*                                    */
  54. /**  4-19-83   BDS C Version file XC.CQ copied from Laurel RCPM       WHR    */
  55. /************************************************************************/
  56. /*                               */
  57. /*    XC  -  A 'C' Concordance Utility               */
  58. /*                               */
  59. /*    Version 1.0   January, 1982               */
  60. /*                               */
  61. /*    Copyright (c) 1982 by Philip N. Hisley           */
  62. /*                               */
  63. /*    Released for non-commercial distribution only       */
  64. /*                               */
  65. /*    Abstract:                           */
  66. /*                               */
  67. /*    'XC' is a cross-reference utility for 'C' programs.  */
  68. /*    Its has the ability to handle nested include files   */
  69. /*    to a depth of 8 levels and properly processes nested */
  70. /*    comments as supported by BDS C. Option flags support */
  71. /*    the following features:                   */
  72. /*                               */
  73. /*    - Routing of list output to disk               */
  74. /*    - Cross-referencing of reserved words           */
  75. /*    - Processing of nested include files           */
  76. /*    - Generation of listing only               */
  77. /*                               */
  78. /*    Usage: xc <filename> <flag(s)>               */
  79. /*                               */
  80. /*    Flags: -i           = Enable file inclusion       */
  81. /*         -l           = Generate listing only       */
  82. /*         -r           = Cross-ref reserved words       */
  83. /*         -o <filename> = Write output to named file       */
  84. /*                               */
  85. /*    Please report bugs/fixes/enhancements to:           */
  86. /*                               */
  87. /*          Philip N. Hisley                   */
  88. /*          548H Jamestown Court               */
  89. /*          Edgewood, Maryland 21040               */
  90. /*          (301) 679-4606                   */
  91. /*          Net Addr: PNH@MIT-AI               */
  92. /*                               */
  93. /***********************************************************/
  94.  
  95. #include <stdio.h>
  96.  
  97. /*
  98.  * Portability Note:  The AZTEC C compilers handle the binary/text file
  99.  * dichotomy differently from most other compilers.  Uncomment the following
  100.  * pair of #defines if you are running AZTEC C:
  101.  */
  102.  
  103. /*
  104. #define getc(f)        agetc(f)
  105. #define putc(c,f)    aputc(c,f)
  106. */
  107.  
  108. /*  Portability Note:  8-bit systems often don't have header files
  109.     ctype.h and string.h.  If your system doesn't have these,
  110.     uncomment the #defines NO_STRING_H and NO_CTYPE_H.           WCC    */
  111.  
  112. /*
  113. #define     NO_STRING_H
  114. #define     NO_CTYPE_H
  115. */
  116.  
  117. /*  Portability Note:  Some older compilers call the function malloc()
  118.     by its older name alloc().    If you have one of these older
  119.     compilers, uncomment the following #define.            WCC    */
  120.  
  121. /*
  122. #define     malloc(x)    alloc(x)
  123. */
  124.  
  125. /*  Portability Note:  A few compilers don't know the additional type
  126.     void.  If yours is one of these, uncomment the following #define.    */
  127.  
  128. /* #define    void        int                    */
  129.  
  130. #ifdef     NO_CTYPE_H                        /* WCC */
  131. int isalpha(), isdigit(), isupper(), toupper();
  132. #else
  133. #include <ctype.h>                        /* WHR */
  134. #endif
  135.  
  136. #ifdef     NO_STRING_H                        /* WCC */
  137. int strcmp();  char *strcpy();
  138. #else
  139. #include <string.h>
  140. #endif
  141.  
  142. #ifndef     abs                            /* WCC */
  143. #define     abs(x)        ((x < 0) ? (-x) : (x))
  144. #endif
  145.  
  146. /*  Portability Note:  Some stdio.h files define various of these
  147.     constants.    Some don't.  Therefore, each definition is
  148.     compiled only if needed.                       WCC */
  149.  
  150. #ifndef     NULL                            /* WCC */
  151. #define     NULL        0
  152. #endif
  153.  
  154. #ifndef     FALSE                            /* WCC */
  155. #define     FALSE        0                        /* WHR */
  156. #endif
  157.  
  158. #ifndef     TRUE                            /* WCC */
  159. #define     TRUE        1                        /* WHR */
  160. #endif
  161.  
  162. #define     MAX_REF    5        /* maximum refs per ref-block */
  163. #define     MAX_LEN    20        /* maximum identifier length  */
  164. #define     MAX_WRD   749        /* maximum number of identifiers */
  165. #define     MAX_ALPHA  53        /* maximum alpha chain heads */
  166. #define     REFS_PER_LINE    8    /* maximum refs per line */
  167. #define     LINES_PER_PAGE 60
  168. #define     FF 0x0C         /* formfeed */
  169.  
  170. /*  Order of the next two structure declarations reversed to avoid
  171.     a forward reference that chokes some compilers.            WCC */
  172.  
  173. struct rf_blk {
  174.          int ref_item[MAX_REF];
  175.          int ref_cnt;
  176.          struct rf_blk *ref_lnk;
  177.            } onerf;
  178.  
  179. struct id_blk {
  180.          char id_name[MAX_LEN];
  181.          struct id_blk *alp_lnk;
  182.          struct rf_blk *top_lnk;
  183.          struct rf_blk *lst_lnk;
  184.            } oneid, *id_vector[MAX_WRD];
  185.  
  186. struct alp_hdr { struct id_blk *alp_top;
  187.            struct id_blk *alp_lst;
  188.          } alp_vector[MAX_ALPHA];
  189.  
  190. int    linum;        /* line number */
  191. int    edtnum;        /* edit line number */
  192. int    fil_cnt;    /* active file index */
  193. int    wrd_cnt;    /* token count */
  194. int    pagno;        /* page number */
  195. int    id_cnt;        /* number of unique identifiers */
  196. int    rhsh_cnt;    /* number of conflict hits */
  197. int    filevl;        /* file level  */
  198. int    paglin;        /* page line counter */
  199. int    prt_ref = FALSE;
  200. char    act_fil[MAX_LEN];
  201. char    lst_fil[MAX_LEN];
  202. char    gbl_fil[MAX_LEN];
  203. FILE   *l_buffer;                         /* WHR */
  204. int    e_flg = FALSE, i_flg = FALSE, o_flg = FALSE;         /* WHR */
  205. int    r_flg = FALSE, l_flg = FALSE, debug = FALSE;         /* WCC */
  206. char    Epson[]     = "\033@\017\033Q\204";             /* WCC */
  207.  
  208. void exit();
  209.  
  210. /*-------------------------------------------*/
  211.  
  212. void main(argc,argv)
  213. int    argc;
  214. char    **argv;
  215. {
  216.      char  *arg, cc;
  217.      void nl(), prnt_tbl(), proc_file(), use_err();
  218.  
  219.      if (argc < 2) use_err();
  220.      (void)strcpy(gbl_fil,*++argv);
  221.      --argc;
  222.      if(gbl_fil[0] == '-')
  223.       use_err();
  224.      while(--argc != 0)
  225.      {      if(*(arg=*++argv) == '-')
  226.     /*****{    switch( toupper(*++arg) )     *** side effect in Microsoft C */
  227.       {    switch( cc=*++arg, toupper(cc) )             /* Microsoft C */
  228.            {   case 'I':  i_flg++;
  229.                   break;
  230.            case 'R':  r_flg++;
  231.                   break;
  232.            case 'L':  l_fl